﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Planer.Model;

namespace Planer.UI.Forms
{
    public partial class AddFinancicalGoalFrom : Form
    {
        public AddFinancicalGoalFrom()
        {
            InitializeComponent();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            string summ = textBoxSumm.Text.Trim().Replace('.', ',');
            float money = 0;
            try
            {
                money = Convert.ToSingle(summ);
            }
            catch (Exception ex)
            {
                MessageBoxUtils.ShowErrorBox("Некорректно введена сумма");
                return;
            }
            

            financial_goal goal = new financial_goal()
            {
                balance = 0,
                closed = "n",
                create_date = DateTime.Now,
                descr = textBoxDescription.Text,
                modify_date = DateTime.Now,
                name = textBoxName.Text,
                necessary = money,
                spent = "n",
                user = Program.CurrentUser
            };
            ModelResult mr = FinancicalGoalModel.GetInstance().SaveOrUpdateFinancicalGoal(goal);
            if (mr.Status == OperationStatusType.ERROR)
            {
                MessageBoxUtils.ShowErrorBox(mr.ShowAllMessages);
                return;
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
